package bdu;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import bdu.test.RobotTestBed;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;

/**
 * Illustrates JUnit testing of Robocode robots. This test verifies that Scavenger is always
 * in a reverse direction movement.
 * 
 * @author Bao Huy Ung
 * 
 */
public class TestScavengerMovement extends RobotTestBed {

  boolean directionCheck;

  /**
   * Specifies that SittingDuck and Scavenger are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,bdu.Scavenger";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * Checks to see if robot is always moving backwards, will always have a negative velocity.
   * 
   * @param event End of a robot's turn cycle
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    // Get and store information on scavenger
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];

    // check to see if it is moving backwards, velocity has to always be negative
    if (robot.getVelocity() <= 0) {
      directionCheck = true;
    }
    else {
      directionCheck = false;
    }
  }

  /**
   * The actual test, which asserts that scavenger maintains a negative velocity.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Unmatched turn radius", directionCheck);
  }
}
